package com.pug.service.user;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pug.mapper.user.UserMapper;
import com.pug.pojo.KssUser;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 飞哥B站地址：https://space.bilibili.com/490711252
 * 记得关注和三连哦！
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2022/3/16$ 23:42$
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, KssUser> implements IUserService {
    @Resource
    RestTemplate restTemplate;
    @Resource
    UserServiceImpl userService;
    /**
     * 根据用户手机号码查询用户
     *
     * @param phone
     * @return
     */
    @Override
    public KssUser getByPhone(String phone) {
        LambdaQueryWrapper<KssUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(KssUser::getPhone, phone);
        return this.getOne(lambdaQueryWrapper);
    }

    @Override
    public boolean updateAvatarById(Long id, String newAvatar) {
        return this.baseMapper.updateAvatarById(id,newAvatar);
    }

    @Override
    public boolean updateBgImgById(Long id, String newBgImg) {
        return this.baseMapper.updateAvatarById(id,newBgImg);
    }

    @Override
    public KssUser selectByPhone(String phone) {
        return this.baseMapper.selectByPhone(phone);
    }
    //获取微信信息
//    public WeiXinData getOpenId(WeiXinData weiXinData){
//        String code=weiXinData.getCode();
//        String url="https://api.weixin.qq.com/sns/jscode2session" + "?appid="+"wx1a19ee1c4e70955f"+"&secret="+"1ace9788794494f9b7af4257231de988"+"&js_code="+code+"&grant_type=authorization_code";
//        ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
//        System.out.println(forEntity);
//        return null;
//    }
}
